<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class image_list_model extends Model
{
	var $url_prefix = 'admin/image.image.lists';
	var $url_prefix2 = 'admin/image.image.detail';
	var $start_segment = 3;
	var $start;
	var $msg_cache_prefix = 'msg';
	var $filter_cache_prefix = 'filter';
	var $cache;
	var $cache_name = 'image';
	var $columns = array();
	var $item_segment = 4;
	var $error_string = '';
	
	function image_list_model()
	{
		parent::Model();
		
		global $CI;
		$start = $CI->uri->segment($this->start_segment);
		$this->start = $start?$start:0;
		
		$this->cache = new Session_lite($this->cache_name);
		
		$this->columns = array(
			'id'=>IMAGE.'.'.IMAGE_IMAGE_ID,
			'name'=>IMAGE.'.'.IMAGE_NAME,
			'thumb_location'=>IMAGE.'.'.IMAGE_THUMB_LOCATION,
		);
	}	
	
	function check_delete($id)
	{
		$q = $this->db->get_where(LINK, array(LINK_FRANCHISE_ID=>$this->admin_id(), LINK_IMAGE_ID=>$id));
		if ($q->num_rows())
		{
			$this->error_string .= "Dependency Error! This image (#{$id}) is used in Link. Please Change it firstly.";
			return false;
		}
		$q = $this->db->get_where(LOCATION, array(LOCATION_FRANCHISE_ID=>$this->admin_id(), LOCATION_IMAGE_ID=>$id));
		if ($q->num_rows())
		{
			$this->error_string .= "Dependency Error! This image (#{$id}) is used in Location. Please Change it firstly.";
			return false;
		}
		$q = $this->db->get_where(PRODUCT, array(PRODUCT_FRANCHISE_ID=>$this->admin_id(), PRODUCT_IMAGE_ID=>$id));
		if ($q->num_rows())
		{
			$this->error_string .= "Dependency Error! This image (#{$id}) is used in Product. Please Change it firstly.";
			return false;
		}
		$q = $this->db->get_where(STAGE, array(STAGE_FRANCHISE_ID=>$this->admin_id(), STAGE_IMAGE_ID=>$id));
		if ($q->num_rows())
		{
			$this->error_string .= "Dependency Error! This image (#{$id}) is used in Stage. Please Change it firstly.";
			return false;
		}
		$q = $this->db->get_where(TEAM, array(TEAM_FRANCHISE_ID=>$this->admin_id(), TEAM_IMAGE_ID=>$id));
		if ($q->num_rows())
		{
			$this->error_string .= "Dependency Error! This image (#{$id}) is used in Team. Please Change it firstly.";
			return false;
		}		
		return true;
	}
}

?>
